package cn.com.nou.common.builder;

import cn.com.nou.common.entity.Pagination;

import java.util.List;

/**
 * 分页构造器
 * @author lixuefeng
 */
public class PaginationBuilder {
    private int total;
    private List<?> resultList;
    
    private int offet;
    private int limit;

    public PaginationBuilder setTotal(int total) {
        this.total = total;
        return this;
    }

    public PaginationBuilder setResultList(List<?> resultList) {
        this.resultList = resultList;
        return this;
    }

    public Pagination build() {
        return new Pagination(this.resultList, this.total);
    }
    
    
    public Pagination getPaginating(int pageNo,int pageSize) {
    	if (pageNo > 0) {
    		this.offet = (pageNo -1) * pageSize;
		}else {
			this.offet = 1;
		}
    	this.limit = pageSize;
    	
        return new Pagination(this.offet, this.limit);
    }
}
